<!--
*Author：jxx
 *Contact：283591387@qq.com
 *代码由框架生成,任何更改都可能导致被代码生成器覆盖
 *业务请在@/extension/mall/GroupCampphase.js此处编写
 -->
 <template>
  <div>
    <view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields"
      :editFormFileds="editFormFields" :editFormOptions="editFormOptions"
      :searchFormFields="searchFormFields" :searchFormFileds="searchFormFields"
      :searchFormOptions="searchFormOptions" :table="table" :extend="extend">
    </view-grid>
  </div>
</template>

<script>
import extend from "@/extension/mall/campEmployees.js";
import ViewGrid from "@/components/basic/viewT.vue";
var vueParam = {
  components: {
    ViewGrid,
  },
  data() {
    function sum(arr) {
      return arr.reduce(function (total, value) {
        return total + value;
      }, 0);
    }
    function groupTeacher(params) {
      let a = [];
      params.forEach((i) => {
        i.forEach((j) => {
          a.push(j.groupTeacher.length);
        });
      });
      return sum(a);
    }
    return {
      table: {
        key: "phase_id_fk",
        footer: "Foots",
        cnName: "营地员工",
        name: "V_campphase",
        url: "/V_campphase/",
        sortName: "createDate",
      },
      extend: extend,
      editFormFields: {},
      editFormOptions: [],
      searchFormFields: { phase_name: "" },
      searchFormOptions: [
        [{ title: "营期名称", field: "phase_name", type: "text" }],
      ],
      columns: [
        {
          field: "campsite_name",
          title: "营种名称",
          type: "int",
          width: 90,
          align: "left",
        },
        {
          field: "phase_name",
          title: "营期名称",
          type: "string",
          width: 120,
          require: true,
          align: "left",
        },
        {
          field: "battalioncommander",
          title: "营长人数",
          type: "int",
          width: 120,
          align: "left",
          render: (h, { row, column, index }) => {
            return h(
              "span",
              {},
              row.battalioncommander != null
                ? row.battalioncommander.split(",").length
                : 0
            );
          },
        },
        {
          field: "deputyBattalionCommander",
          title: "副营长人数",
          type: "int",
          width: 120,
          align: "left",
          render: (h, { row, column, index }) => {
            return h(
              "span",
              {},
              row.deputyBattalionCommander != null
                ? row.deputyBattalionCommander.split(",").length
                : 0
            );
          },
        },
        {
          field: "teamTeacher",
          title: "团队老师人数",
          type: "int",
          width: 120,
          align: "left",
          render: (h, { row, column, index }) => {
            return h(
              "span",
              {},
              row.teamTeacher != null && row.teamTeacher != "null"
                ? sum(
                    JSON.parse(row.teamTeacher).map((i) => i.teamTeacher.length)
                  )
                : 0
            );
          },
        },
        {
          field: "groupTeacher",
          title: "小组老师人数",
          type: "int",
          width: 120,
          align: "left",
          render: (h, { row, column, index }) => {
            return h(
              "span",
              {},
              row.groupTeacher != null && row.groupTeacher != "[]" && row.groupTeacher != "null"
                ? groupTeacher(JSON.parse(row.groupTeacher))
                : 0
            );
          },
        },
        {
          field: "groupnum",
          title: "状态",
          type: "int",
          width: 120,
          align: "left",
        },
      ],
      detail: {
        cnName: "#detailCnName",
        columns: [],
        sortName: "",
        key: "",
      },
    };
  },
};
export default vueParam;
</script>
